package com.newbingo.service;

import java.util.Date;

import com.newbingo.dao.imple.IMemberDao;
import com.newbingo.dao.imple.ITradeRecordDao;
import com.newbingo.dto.imple.ITradeRecordDto;
import com.newbingo.entity.Member;
import com.newbingo.entity.TradeRecord;
import com.newbingo.service.imple.ITradeRecordService;
import com.newbingo.util.Pager;

/**
 * 交易记录Service
 * @author ChansonYan
 *
 */
public class TradeRecordService implements ITradeRecordService {
	private ITradeRecordDao tradeRecordDao;
	private ITradeRecordDto tradeRecordDto;
	private IMemberDao memberDao;

	/* 
	 * 分页查询，返回TradeRecordDto对象
	 */
	public Pager findByPage(int start,int limit,Integer uno){
		return tradeRecordDto.findByPage(start, limit, uno);
	}
	
	/*
	 * 保存会员充值提现信息
	 */
	public void saveTrade(Integer uno,Integer score,String tradeType){
		TradeRecord tradeRecord=new TradeRecord();
		//根据会员ID查询出会员的对象，并对属性赋值
		Member member=memberDao.findById(uno);	
		if(tradeType.equals("提现"))
			member.getAccount().setAmount(member.getAccount().getAmount()-score);
		else
			member.getAccount().setAmount(member.getAccount().getAmount()+score);
		tradeRecord.setAmount(member.getAccount().getAmount());
		tradeRecord.setScore(score);
		tradeRecord.setTradeTime(new Date());
		tradeRecord.setType(tradeType);
		tradeRecord.setMember(member);
		tradeRecordDao.save(tradeRecord);
	}
	
	public ITradeRecordDao getTradeRecordDao() {
		return tradeRecordDao;
	}
	public void setTradeRecordDao(ITradeRecordDao tradeRecordDao) {
		this.tradeRecordDao = tradeRecordDao;
	}
	public ITradeRecordDto getTradeRecordDto() {
		return tradeRecordDto;
	}
	public void setTradeRecordDto(ITradeRecordDto tradeRecordDto) {
		this.tradeRecordDto = tradeRecordDto;
	}
	
	public IMemberDao getMemberDao() {
		return memberDao;
	}
	public void setMemberDao(IMemberDao memberDao) {
		this.memberDao = memberDao;
	}
	
}
